package leetcode

//https://leetcode.com/problems/remove-duplicates-from-sorted-array/

fun main(args: Array<String>) {

    println(removeDuplicatesOfSortedArray(intArrayOf(0, 0, 0, 1)))

}

fun removeDuplicatesOfSortedArray(nums: IntArray): Int {


    var r = nums.size

    var i = 0

    //下标移动到最后一个元素即终止
    while (i + 1 < r) {

        if (nums[i + 1] == nums[i]) {

            //删除 i+1 位置的元素,即整体前移

            var j = i + 1
            while (j+1  < nums.size) {
                nums[j] = nums[j + 1]
                j++
            }

            r--
            //继续比较后面的元素
            continue
        }

        i++
    }


    return r;
/*    var result = nums.size

    var i = 0
    while (i < result){
        if (i+1< nums.size){
            if (nums[i+1] == nums[i]){
                result--
                switchAfter(i+1,nums)
            }else i++
        }else break

    }
    return result*/
}